<template>
    <!-- 待处理事项模块-差错登记管理 -->
    <div class="fillcontain" v-loading="loading" style="padding: 0px 0px;">
			<el-form  :model="searchParams"  label-width="100px" >
			<el-row>
			<el-col :span="6">
				<el-form-item label="接口选择" prop="changeAB">
					<el-select @change="changeSelect"  v-model="searchParams.changeAB" placeholder="接口选择">
						<el-option v-for="item in interfaces" :key="item.value" :label="item.name"
								:value="item.value"></el-option>
					</el-select>
				</el-form-item>
			</el-col>
			</el-row>
			<el-row>
			<el-col :span="20">
				<el-form-item label="请求报文" prop="requestParams">
					<el-input type="textarea" :rows="8" style="height: 6.25rem;" v-model="searchParams.requestParams" clearable placeholder="请输入请求报文" ></el-input>
				</el-form-item>
			</el-col>
			</el-row>
			<el-row style="margin-top: 0.625rem; float: right;">
			<el-col >
				<el-button type="primary" icon="el-icon-search" @click.native="search">查询</el-button>
			</el-col>
			</el-row >
				<div style="margin-top: 40px;margin-bottom: 40px;"><span>请求总耗时：</span><span id="time"></span> ms</div>
			<el-row style="margin-top: 0.325rem;">
				<el-col :span="20">
					<el-form-item label="返回报文">
					<el-input type="textarea" :rows="10" readonly style="margin: 0.325rem 1.225rem 0 0.625rem;" id="resultJson"></el-input>
					</el-form-item>
				</el-col>
			</el-row>
			</el-form>
	</div>
</template>

<script>
	import {
		mapGetters
	} from 'vuex'
	import { getToken} from '@/utils/auth';
    import constant from '@/utils/constant';
	import TaskConstants  from "@/api/taskManager/common"
    export default {
        data() {
            return {
				interfaces: [
					{name:"累计保额接口",value:"calculationA"},
					{name:"保费计算接口",value:"calculationB"},
					{name:"中文名转CDFS三位码",value:"calculationC"},
					{name:"CDFS三位码转polpln",value:"calculationD"},
					{name:"第三方接口",value:"calcultionE"},
				],
				loading: false,
				resultJson:'',
				searchParams:{
					changeAB:'calculationA',
					requestParams:'',
				},
                // 查询条件
            }
        },
        created() {
        },
        mounted() {

        },
        methods: {
			changeSelect(){
				document.getElementById("resultJson").value='';
				document.getElementById("time").innerHTML='';
				this.searchParams.requestParams='';
			},
            // 加载cdfs的差错查询列表
            search() {
				this.$store.dispatch('loading/CHANGE_LOADING',true);
				let check = this.searchParams.changeAB;
				let param = this.searchParams.requestParams;
				document.getElementById("resultJson").value='';
				if (param =="") {
					this.$message.error("请输入请求入参！");
						this.$store.dispatch('loading/CHANGE_LOADING',false);
					return;
				}
				let url ='';
				if (check =='calculationA') {
					url=TaskConstants.apis.calcultionA;
				} else if(check =='calculationB') {
					url=TaskConstants.apis.calcultionB;
				} else if (check == 'calculationC') {
					url=TaskConstants.apis.calcultionC;
				} else if (check == 'calculationD'){
					url=TaskConstants.apis.calcultionD;
				}else{
					url=TaskConstants.apis.calcultionE;
				}
				let that =this;
				let start = new Date();
				this.$.ajax({
					headers: {
					Authorization: getToken(constant.TOKEN) || '',
					'Content-Type':'application/json;charset=UTF-8'
					},
					url: url,//url路径
					type: 'POST', 
					data: param,
					success: function (res) {
						that.$store.dispatch('loading/CHANGE_LOADING',false);
						if(check == 'calcultionE'){
							console.info("接口返回",res)
							document.getElementById("resultJson").value = JSON.stringify(res);
							let end = new Date();
							document.getElementById("time").innerHTML=(end.getTime() -start.getTime())
							return ;
						}
						if (res.resultCode == constant.SUCCESS && res.data != null) {
							document.getElementById("resultJson").value = JSON.stringify(res.data);
							let end = new Date();
							document.getElementById("time").innerHTML=(end.getTime() -start.getTime())
						} else{
							document.getElementById("resultJson").value = res.resultMsg;
						}

					},
					error:function(){
						that.$store.dispatch('loading/CHANGE_LOADING',false);
					}
				});
            },
        },
		computed: {
			...mapGetters(['tags']),
			reload() {
				return this.$store.state.loading.reload;
			}
		},
    }
</script>



